'use strict';
app.controller('consumerTopCtrl', ['$scope', 'utilService', 'consumerTopService', 'toaster', '$modal', '$filter',
    function ($scope, utilService, consumerTopService, toaster, $modal, $filter) {
        $scope.consumerTop = {};
        $scope.consumerTop.startTime = new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-01";
        $scope.consumerTop.endTime = $filter('date')(new Date(), 'yyyy-MM-dd');

        $scope.convert = function () {
            if ($scope.consumerTop.startTime != null) {
                $scope.consumerTop.startTime = $filter("date")($scope.consumerTop.startTime, "yyyy-MM-dd");
            }
            if ($scope.consumerTop.endTime != null) {
                $scope.consumerTop.endTime = $filter("date")($scope.consumerTop.endTime, "yyyy-MM-dd");
            }
        };

        $scope.query = function () {
            $scope.convert();
            utilService.queryForPagingList($scope, {
                url: $scope.app.domain + "pay/history/ranking",
                params: $scope.consumerTop
            }).then(function (result) {
            })
        };
        $scope.query();

        $scope.openExportDate = function () {
            openModal("确定要导出已查询出的记录吗？" +
                "(导出时间跟导出数据量的大小有关，请耐心等待)");
            function openModal(msg) {
                utilService.modal($modal, $scope, {
                    title: "温馨提示",
                    controller: "exportDataCtrl",
                    message: msg,
                    data: $scope.consumerTop
                });
            }
        }
    }]);


app.controller('userConsumerCtrl', ['$scope', 'utilService', 'consumerTopService', 'toaster', '$stateParams', '$modal',
    function ($scope, utilService, consumerTopService, toaster, $stateParams, $modal) {
        $scope.userConsumer = {};
        $scope.userId = $stateParams.id;
        $scope.getUserHistory = function () {
            utilService.queryForPagingList($scope, {
                url: $scope.app.domain + "pay/history/get",
                params: {userId: $scope.userId}
            }).then(function (result) {
            })
        };

        $scope.getUserHistory();

        $scope.openExportDate = function () {
            openModal("确定要导出已查询出的记录吗？" +
                "(导出时间跟导出数据量的大小有关，请耐心等待)");
            function openModal(msg) {
                utilService.modal($modal, $scope, {
                    title: "温馨提示",
                    controller: "userExportDataCtrl",
                    message: msg,
                    data: $scope.userId
                });
            }
        }
    }]);

app.controller('exportDataCtrl', ['$scope', '$modalInstance', '$state', 'consumerTopService', 'toaster', 'modalData',
    function ($scope, $modalInstance, $state, consumerTopService, toaster, modalData) {
        $scope.modal = modalData;
        $scope.params = modalData.data;
        $scope.AllowToDelete = true;

        $scope.ok = function () {
            if (!$scope.AllowToDelete) {
                return;
            }
            $scope.AllowToDelete = false;
            consumerTopService.exportData($scope);
            $modalInstance.dismiss('success');
        };
        //取消弹窗
        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };
    }
]);

app.controller('userExportDataCtrl', ['$scope', '$modalInstance', '$state', 'consumerTopService', 'toaster', 'modalData',
    function ($scope, $modalInstance, $state, consumerTopService, toaster, modalData) {
        $scope.modal = modalData;
        $scope.param = modalData.data;
        $scope.AllowToDelete = true;

        $scope.ok = function () {
            if (!$scope.AllowToDelete) {
                return;
            }
            $scope.AllowToDelete = false;
            consumerTopService.userExportData($scope);
            $modalInstance.dismiss('success');
        };
        //取消弹窗
        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };
    }
]);